﻿function SadeceRakam(e, allowedchars) {
    var key = e.charCode == undefined ? e.keyCode : e.charCode;
    if ((/^[0-9]+$/.test(String.fromCharCode(key))) || key == 0 || key == 13 || isPassKey(key, allowedchars))
    { return true; }
    else { return false; }
}

function isPassKey(key, allowedchars) {
    if (allowedchars != null) {
        for (var i = 0; i < allowedchars.length; i++) {
            if (allowedchars[i] == String.fromCharCode(key))
                return true;
        }
    } return false;
}

function SadeceRakamBlur(e, clear) {
    var nesne = e.target ? e.target : e.srcElement;
    var val = nesne.value; val = val.replace(/^\s+|\s+$/g, "");
    if (clear) val = val.replace(/\s{2,}/g, " "); nesne.value = val;
}

function VirgulEkle(e) {
    var nesne = e.target ? e.target : e.srcElement;
    var pressedKey = (e.charCode == undefined || e.charCode == 0) ? e.keyCode : e.charCode;
    if (pressedKey != 8) {
        var v = nesne.value;
        if (v.match(/^\d{1}$/) !== null) {
            nesne.value = v + ',';
        }
    }
}

function SaatNoktaEkle(e) {
    var nesne = e.target ? e.target : e.srcElement;
    var pressedKey = (e.charCode == undefined || e.charCode == 0) ? e.keyCode : e.charCode;
    if (pressedKey != 8) {
        var v = nesne.value;
        if (v.match(/^\d{2}$/) !== null) {
            nesne.value = v + ':';
        }
    }
}

function alertOzelLoc(STR,location) {

    var H = $(window).width();
    var tek = $.now();
    var ZENUST = 0;

    $("body").append("<div class='perde' id='" + tek + "'></div>");

    $("div").each(function () {
        var index_current = parseInt($(this).css("zIndex"), 10);
        if (index_current > ZENUST) {
            ZENUST = index_current;
        }
    });

    $("#" + tek).css({ height: H, zIndex: ZENUST }).stop().fadeIn();


    $("body").append("<div class='alertOzelPencere'><div class='mesaj'>" + STR + "</div><div class='butonlar'><div class='btn1' id='alertOzelTamam'>Tamam</div></div></div>");
    $(".alertOzelPencere").css({ zIndex: ZENUST + 1 });

    $("#alertOzelTamam").click(function (e) {
        e.preventDefault();
        e.stopImmediatePropagation();
        $(".alertOzelPencere").remove();
        $("#" + tek).stop().fadeOut(500, function () { $("#" + tek).remove(); });
        if (location != '')
            window.location.href = location;

    })
    $("body").keyup(function (e) {

        var key = e.keyCode ? e.keyCode : e.which;
        if (key == 13) $("#alertOzelTamam").click();


        if (key == 27) {
            //console.log(tek)
            $(".alertOzelPencere").remove();
            $("#" + tek).stop().fadeOut(500, function () { $("#" + tek).remove(); });
        }

    })
}

function alertOzel(STR) {

    var H = $(window).width();
    var tek = $.now();
    var ZENUST = 0;

    $("body").append("<div class='perde' id='" + tek + "'></div>");

    $("div").each(function () {
        var index_current = parseInt($(this).css("zIndex"), 10);
        if (index_current > ZENUST) {
            ZENUST = index_current;
        }
    });

    $("#" + tek).css({ height: H, zIndex: ZENUST }).stop().fadeIn();


    $("body").append("<div class='alertOzelPencere'><div class='mesaj'>" + STR + "</div><div class='butonlar'><div class='btn1' id='alertOzelTamam'>Tamam</div></div></div>");
    $(".alertOzelPencere").css({ zIndex: ZENUST + 1 });

    $("#alertOzelTamam").click(function (e) {
        e.preventDefault();
        e.stopImmediatePropagation();
        $(".alertOzelPencere").remove();
        $("#" + tek).stop().fadeOut(500, function () { $("#" + tek).remove(); });
        window.location.href = "AnaSayfa.aspx";

    })
    $("body").keyup(function (e) {

        var key = e.keyCode ? e.keyCode : e.which;
        if (key == 13) $("#alertOzelTamam").click();


        if (key == 27) {
            //console.log(tek)
            $(".alertOzelPencere").remove();
            $("#" + tek).stop().fadeOut(500, function () { $("#" + tek).remove(); });
        }

    })
}

function kontrolEt(id, compare) {
    var val = $(id).val();
    var dil = getCookie('dil');
    var hata;
    if (dil == 'TR')
        hata = 'Boş Bırakmayın';
    else
        hata = 'Required Field';
    if (val == compare)
        return hataGoster(id, hata);
    else
        return true;
}

function hataGoster(ID, HATA) {


    var eleman = "";
    if (ID instanceof jQuery) {
        eleman = ID;
    } else {
        eleman = $(ID);

    }

    eleman.after("<div class='inputhata'>" + HATA + "</div>");
    var XPOS = eleman.position().left + eleman.width() + 0;
    var YPOS = eleman.position().top + 3;
    $(".inputhata").css({ left: XPOS + "px", top: YPOS + "px" });
    //eleman.css({backgroundColor:"#f00"})
    eleman.focus(function () {
        $(this).next(".inputhata").remove();
    });

    setTimeout(function () { $(".inputhata").remove(); }, 2000);
    $('html, body').animate({ scrollTop: $(".inputhata:first").offset().top - 80 }, 600);

    return false;
}


function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function getParameterRoutedUrl() {
    var qs = location.pathname;
    qs = qs.substring(1);

    var a = qs.split('/');
    var i;
    var output = new Array();

    for (i = 0; i < a.length; i += 1) {
        //append key->value pairs to output array
        output[i] = a[i + 1];
    }
    return output;
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function IsEmail(email) {
    var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return regex.test(email);
}
